//
//  JTTopicVideoView.m
//  百思不得姐
//
//  Created by Robin Zhang on 2017/1/13.
//  Copyright © 2017年 BeiJingWangDianJieTong. All rights reserved.
//

#import "JTTopicVideoView.h"
#import "JTTopic.h"
#import <UIImageView+WebCache.h>
#import "JTSeeBigPictureViewController.h"

@interface JTTopicVideoView ()

@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UILabel *playCountLabel;
@property (weak, nonatomic) IBOutlet UILabel *videoTimeLabel;

@end

@implementation JTTopicVideoView

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self setAutoresizingMask:UIViewAutoresizingNone];
    
    // 给imageView添加点击手势
    [self.imageView setUserInteractionEnabled:YES];
    [self.imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(seeBig:)]];
    
    /** 清空背景色 */
//    [self.playCountLabel setBackgroundColor:[UIColor clearColor]];
//    [self.videoTimeLabel setBackgroundColor:[UIColor clearColor]];
}

- (void)setTopic:(JTTopic *)topic {
    
    _topic = topic;
    
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:topic.largeImage]];
    [self.playCountLabel setText:[NSString stringWithFormat:@"%ld次播放", topic.playcount]];
    NSInteger minute = topic.videotime / 60;
    NSInteger second = topic.videotime % 60;
    
    /** 
     %04ld - 占据4位，多余的用0来填补
     */
    [self.videoTimeLabel setText:[NSString stringWithFormat:@"%02ld:%02ld", minute, second]];
}

#pragma mark - 监听
- (void)seeBig:(UITapGestureRecognizer *)recognizer {
    
    JTSeeBigPictureViewController *viewController = [[JTSeeBigPictureViewController alloc] init];
    [viewController setTopic:self.topic];
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:viewController animated:YES completion:nil];
}

@end
